package com.lijy.employee.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lijy.employee.dao.EmployeeDao;
import com.lijy.employee.domain.Employee;
import com.lijy.employee.domain.PageBean;
@Service
public class EmployeeServiceImpl implements EmployeeService {

	@Autowired
	private EmployeeDao employeeDao;
	
	@Override
	public void save(Employee employee) {
      employeeDao.save(employee);
	}

	@Override
	public Employee findByUsernameAndPassword(Employee employee) {
		return employeeDao.findByUsernameAndPassword(employee);
	}

	@Override
	public List<Employee> list() {
		return employeeDao.list();
	}

	@Override
	@Transactional
	public PageBean<Employee> findByPage(int currPage) {
		PageBean<Employee> pageBean = new PageBean<Employee>();
		pageBean.setCurrPage(currPage);
		int pageSize = 10;
		pageBean.setPageSize(pageSize);
		int totalCount = employeeDao.findCount();
		pageBean.setTotalCount(totalCount);
		double tc = totalCount;
		Double num = Math.ceil(tc / pageSize);
		pageBean.setTotalPage(num.intValue());
		int begin = (currPage - 1) * pageSize;
		List<Employee> list = employeeDao.findByPage(begin, pageSize);
		pageBean.setList(list);
		return pageBean;
	}

	@Override
	public Employee findById(String eid) {
		return employeeDao.findById(eid);
	}

	@Override
	public void update(Employee employee) {
        employeeDao.update(employee);		
	}

	@Override
	public void delete(String eid) {
		employeeDao.delete(eid);
	}

}
